<?php

namespace Muyuxuanpay\threePay;
/**
 * 服务商进件
 */
class Merchant
{

    /**
     * 获取服务商进件管理器
     * @param $config 配置信息
     * @param $type 类型(公司名)
     * @return mixed|void
     * @throws \Exception
     */
    public static function getIncomingManager($config = [], $type = 'official')
    {
        $types = explode('.', $type);
        $className = __NAMESPACE__ . '\\src\\' . $types[0] . '\\Manager';
        if (!class_exists($className)) {
            throw new \Exception('支付类型错误');
        }
        if(count($types) == 1){
            if(method_exists($className,'getMerchant')){
                return $className::getMerchant($config);
            }else{
                $className2 = __NAMESPACE__ . '\\src\\' . $types[0] . '\\merchant\\Incoming';
                if(!class_exists($className2)){
                    throw new \Exception('支付类型错误');
                }else{
                    return new $className2($config);
                }
            }
        }
        $className2 = __NAMESPACE__ . '\\src\\' . $types[0] . '\\' . $types[1] . '\\Incoming';
        if (!class_exists($className2)) {
            throw new \Exception('支付类型错误');
        }
        return new $className2($config);
    }
}